import { addOverlay, removePopup } from "@/components/map/map";

export default class Effect1 {
  constructor(viewer) {
    this.viewer = viewer;
    this.stage = null;
    this.rainOverlayList = [];

    this.start();
  }

  start() {
    this.viewer.camera.flyTo({
      destination: Cesium.Cartesian3.fromDegrees(
        113.23813733000937,
        27.834779925805126,
        15204.135644681886
      ), //设置位置
      orientation: {
        heading: Cesium.Math.toRadians(339.34309956631967),
        pitch: Cesium.Math.toRadians(-50.23559338091599),
        roll: 0,
      },
    });

    // this.addRainOverlay()
  }

  start2() {
    if (this.stage) {
      this.stage._actualUniforms.rain_density = 0.8;
      this.stage._actualUniforms.size = 2;
      this.stage._actualUniforms.rain_speed = 0.8;
    } else {
      let stage = Cesium.PostProcessStageLibrary.createRainStage({
        density: 0.8, // 密度 值越大雨效果越大
        size: 2, // 粗细 值越大雨效果越大
        speed: 0.8, // 速度 值越大雨效果越大
      });
      this.stage = this.viewer.scene.postProcessStages.add(stage);
    }
  }

  start3() {
    if (this.stage) {
      this.stage._actualUniforms.rain_density = 5;
      this.stage._actualUniforms.size = 8;
      this.stage._actualUniforms.rain_speed = 5;
    } else {
      let stage = Cesium.PostProcessStageLibrary.createRainStage({
        density: 5, // 密度 值越大雨效果越大
        size: 8, // 粗细 值越大雨效果越大
        speed: 5, // 速度 值越大雨效果越大
      });
      this.stage = this.viewer.scene.postProcessStages.add(stage);
    }
  }

  addRainOverlay() {
    let lonlats = [
      {
        lon: 113.19422375847088,
        lat: 27.92603725917949,
        height: 62.2796264650688,
      },
      {
        lon: 113.14814412083176,
        lat: 27.891335189941035,
        height: 56.077752310303595,
      },
      {
        lon: 113.16186946397448,
        lat: 27.788564628662733,
        height: 64.40463988751763,
      },
    ];
    lonlats.forEach((item, index) => {
      let element = document
        .getElementsByClassName("weather-popup")[0]
        .cloneNode(true);
      element.style.display = "block";
      this.rainOverlayList[index] = addOverlay(
        this.viewer,
        element,
        Cesium.Cartesian3.fromDegrees(item.lon, item.lat, item.height),
        0,
        0
      );
    });
  }

  clear() {
    this.viewer.scene.postProcessStages.remove(this.stage);
    this.stage = null;

    // this.rainOverlayList.forEach(item=>{
    //   removePopup(item)
    // })
    // this.rainOverlayList = []
  }
}
